package com.ruoyi.platform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.platform.domain.ActivityRelations;
import com.ruoyi.platform.service.IActivityRelationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动关联Controller
 * 
 * @author ruoyi
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/platform/activity_relations")
public class ActivityRelationsController extends BaseController
{
    @Autowired
    private IActivityRelationsService activityRelationsService;

    /**
     * 查询活动关联列表
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityRelations activityRelations)
    {
        startPage();
        List<ActivityRelations> list = activityRelationsService.selectActivityRelationsList(activityRelations);
        return getDataTable(list);
    }

    /**
     * 导出活动关联列表
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:export')")
    @Log(title = "活动关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityRelations activityRelations)
    {
        List<ActivityRelations> list = activityRelationsService.selectActivityRelationsList(activityRelations);
        ExcelUtil<ActivityRelations> util = new ExcelUtil<ActivityRelations>(ActivityRelations.class);
        util.exportExcel(response, list, "活动关联数据");
    }

    /**
     * 获取活动关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:query')")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") String relationId)
    {
        return success(activityRelationsService.selectActivityRelationsByRelationId(relationId));
    }

    /**
     * 新增活动关联
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:add')")
    @Log(title = "活动关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityRelations activityRelations)
    {
        return toAjax(activityRelationsService.insertActivityRelations(activityRelations));
    }

    /**
     * 修改活动关联
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:edit')")
    @Log(title = "活动关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityRelations activityRelations)
    {
        return toAjax(activityRelationsService.updateActivityRelations(activityRelations));
    }

    /**
     * 删除活动关联
     */
    @PreAuthorize("@ss.hasPermi('platform:activity_relations:remove')")
    @Log(title = "活动关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{relationIds}")
    public AjaxResult remove(@PathVariable String[] relationIds)
    {
        return toAjax(activityRelationsService.deleteActivityRelationsByRelationIds(relationIds));
    }
}
